package com.four.controller;

import com.four.pojo.TicketTemplate;
import com.four.service.TicketTemplateService;
import com.four.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhao
 * @date 2023/1/22  0022 22:36:14
 */
@RestController
@RequestMapping("ticketTemplate")
@CrossOrigin("*")
public class TicketTemplateController {

    @Autowired
    private TicketTemplateService templateService;

    @PostMapping("createTicket")
    public void createTicketTemplate(TicketTemplate ticketTemplate) {
        templateService.createTicketTemplate(ticketTemplate);
    }

    @GetMapping("findAvailableTicket")
    public JsonResult findAvailableTicket() {
        List<TicketTemplate> availableTicket = templateService.findAvailableTicket();

        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setData(availableTicket);

        return jsonResult;
    }

    @GetMapping("findById")
    public JsonResult findById(Integer id) {
        TicketTemplate ticketTemplate = templateService.findById(id);

        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setData(ticketTemplate);

        return jsonResult;
    }
}
